/**
 * Arduino两轮小车
 * 
 * 本程序可不受限制的用于学习和教学，商业用途请联系作者。
 * 本程序不对用户因使用程序而造成任何形式的损失负责。
 * 
 * site: http://www.xpstem.com/maker/arduino-vehicle
 * author: billy zhang
 */
 
#ifndef ARDUINO_INFRARED_RECEIVER_H_
#define ARDUINO_INFRARED_RECEIVER_H_

#include <IRremote.h>
#include "RemoteReceiver.h"

/**
 * 红外线控制器类
 * 
 * 接收红外线遥控器发送的信息，转换为小车控制动作。
 * 需红外线接收管、红外遥控器配套使用。
 */
class InfraredReceiver : public RemoteReceiver
{
   public:
     InfraredReceiver(uint8_t irrecvPin)
      : irrecv_(IRrecv(irrecvPin))
     {
     }

     void setup() override;
     void receive() override;

     uint8_t leftPressState() override { return leftPressState_; }
     uint8_t rightPressState() override { return rightPressState_; }
     uint8_t forwardPressState() override { return forwardPressState_; }
     uint8_t backwardPressState() override { return backwardPressState_; }
     uint8_t accelPressState() override { return accelPressState_; }
     uint8_t stopPressState() override { return stopPressState_; }
     
     int angleValue() override { return angleValue_; }
     int accelValue() override { return accelValue_; }
    
     ~InfraredReceiver();

  private:

    const IRrecv& irrecv_;
    decode_results results_;
    
     uint8_t leftPressState_=0;
     uint8_t rightPressState_=0;
     uint8_t forwardPressState_=0;
     uint8_t backwardPressState_=0;
     uint8_t accelPressState_=0;
     uint8_t stopPressState_=0;

     int accelValue_=0;
     int angleValue_=0;
};

#endif
